package com.alibaba.dubbo.remoting.interceptor;

import java.net.InetAddress;

import com.alibaba.dubbo.common.inet.InetAddressProvider;
import com.alibaba.dubbo.common.inet.InetAddressProviderAware;
import com.alibaba.dubbo.common.inet.ipv4.AddressMatcher;

/**
 * 
 * @author kingbo.ruan
 * 2014年9月25日 上午8:43:25
 */
public class BlackListInterceptorBasedAddressProvider extends BlackListInterceptor implements InetAddressProviderAware {
	private AddressMatcher matcher = null;
	@Override
	public boolean match(InetAddress address) {
		//是否有同步问题？
		if(matcher == null){
			InetAddressProvider provider = this.getInetAddressProvider();
			matcher = new AddressMatcher();
			if(provider != null) {
				matcher.setInetAddressProvider(provider);
			}
		}
		
		return matcher.match(address);
	}
	
	private InetAddressProvider provider;
	@Override
	public InetAddressProvider getInetAddressProvider() {
		return provider;
	}
	
	public void setInetAddressProvider(InetAddressProvider provider) {
		this.provider = provider;
	}
}
